package UIFree.FX
{
	import UIFree.FX;
	import UIFree.FXContainer;
	import UIFree.FXEvent;
	import UIFree.uif_ecomponent;
	
	import flash.display.DisplayObject;
	import flash.events.Event;
	
	public class fx_runningProperty extends Object {
		private var _control: DisplayObject;
		private var _props: Object;
		public function fx_runningProperty(a_control: DisplayObject) {
			super();
			_control = a_control;
			_props	= new Object();
			_control.addEventListener(uif_ecomponent.DISPOSE, doDispose);
		}
		
		protected function doDispose(e: Event): void {
			FXCancel();
		}
		
		protected function pfx(propertyName: String, a_from: *, a_to:*, 
								a_transition: Function=null, fps: int=16, duration: int=500): FX {
			if (_props[propertyName])
				(_props[propertyName] as FX).cancel();
						
			var _fx: FXContainer = new FXContainer(_control, propertyName, a_from, a_to, 
								function(e: FXEvent): void {
				_props[propertyName].dispose();
				delete(_props[propertyName]);
			}, a_transition, fps, duration);
			
			_props[propertyName] = _fx;
			return _fx;
									
		}
		
		public function fx(propertyName: String, a_from: *, a_to:*, 
								a_transition: Function=null, fps: int =16, 
								duration: int=500): FX {
			return pfx(propertyName, a_from, a_to, a_transition, fps, duration);
		}
		
		public function FXCancel(): void {
			for (var propertyName: String in _props) FXNameCancel(propertyName);
		}
		
		public function FXNameCancel(propertyName: String): void {
			if (_props.hasOwnProperty(propertyName)) {
				(_props[propertyName] as FX).cancel();
				delete(_props[propertyName]);
			}
		}
		
		public function getFX(propertyName: String): FX {
			if (_props != null)
				return _props.hasOwnProperty(propertyName)?(_props[propertyName] as FX):null;
			else return null;
		}
		
	}
}